import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:zz_listen_english/common/api/http_head.dart';
import 'package:zz_listen_english/common/extension/ex_list.dart';
import 'package:zz_listen_english/common/models/plan/plan_study_model.dart';
import 'index.dart';

class AudioPlayPage extends GetView<AudioPlayController> {
  const AudioPlayPage({super.key});

  // 主视图
  Widget _buildView() {
    return
      [
        _buildImageHead(),
        // _buildAudioNameHead(),
        // _buildPosition(),
        _buildVolumeHead(),
        _buildAudioList(),
      ].toColumn();
  }

//播放的图片
  Widget _buildImageHead() {
    return [
      TextButton(
          onPressed: () => {controller.showPicker()},
          child: Text(controller.studyPlanName)),
    ].toColumn(mainAxisAlignment: MainAxisAlignment.end);
  }

// //图片下的名称
//   Widget _buildAudioNameHead() {
//     return [
//       Text(
//         controller.planStudy.fileName ?? "",
//         style: TextStyle(fontSize: 16),
//       )
//     ].toColumn();
//   }

//volume
  Widget _buildVolumeHead() {
    return [
      TextButton(
          onPressed: () => {controller.orderPlayModel()},
          child: const Text("顺序播放")),
      TextButton(
          onPressed: () => {controller.player.stop()},
          child: const Text("暂停")),
      TextButton(
          onPressed: () => {controller.shufflePlayModel()},
          child: const Text("随机播放")),
    ].toRow(mainAxisAlignment: MainAxisAlignment.center);
  }

  Widget _buildAudioList() {
    List<PlanStudyModel> audioList = controller.audioUrlList!;
    List<Widget> list = [];
    for (int i = 0; i < audioList.length; i++) {
      PlanStudyModel item = audioList[i];
      list.add(ListTile(
          title: InkWell(
            onTap: () {
              // 点击事件的处理函数
              controller.playAudio(i, item);
            },
            child: Text(
              "${i + 1}.${item.fileName!}",
              style: const TextStyle(
                color: Colors.black,
                decoration: TextDecoration.underline,
              ),
            ),
          )));
    }
    return SizedBox(height: 880.h, child: ListView(children: list));
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<AudioPlayController>(
      init: AudioPlayController(),
      id: "audio_play",
      builder: (_) {
        return Scaffold(
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }
}
